package com.medisign.sign.log.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

    private static final Log log = LogFactory.getLog(DateUtil.class);

    public static Date defaultStartDate() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String defaultDateStr = "2019-01-01 00:00:00";
        try {
            return sdf.parse(defaultDateStr);
        } catch (ParseException e) {
            log.error("获取默认时间失败: {}", e);
            throw new RuntimeException("获取默认时间失败!");
        }
    }

    public static Date strToDate(String dateStr) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return sdf.parse(dateStr);
        } catch (ParseException e) {
            log.error("解析时间失败: {}", e);
            throw new RuntimeException("获取默认时间失败!");
        }
    }

    public static String dateToStr(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }

}
